package com.oss.validation;

import com.oss.model.Tag;
import org.springframework.util.StringUtils;
import org.springframework.validation.Errors;

/**
 * @author xueqiang.mi
 * @date 2010-2-2
 */
public class TagValidator {

	public void validate(Tag tag, Errors errors) {

		if (!StringUtils.hasLength(tag.getId())) {
			errors.rejectValue("id", "required", "required");
		}

		if (!StringUtils.hasLength(tag.getName())) {
			errors.rejectValue("name", "required", "required");
		}

		if (tag.getDescription().length() > 100) {
			errors.rejectValue("description", "valid",
					"must not longer than 100 bytes");
		}
	}
}
